package pl.hexar.action;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.hibernate.validator.Length;
import org.jboss.seam.annotations.Name;

@Name("passwordBean")
public class PasswordBean {

    private String password;
    private String confirm;

    public PasswordBean() {
    }
    
    @Length(min=5,max=40)
    public String getPassword() {
        return password;
    }

    
    public void setPassword(String password) {
        this.password = password;
    }
    
    @Length(min=5,max=40)
    public String getConfirm() {
        return confirm;
    }

    public void setConfirm(String confirm) {
        
        this.confirm = confirm;
        
        boolean passNotMatch = (!confirm.equals(this.password) && !confirm.equals("") && confirm != null);

        if (passNotMatch) {
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage msg = new FacesMessage("Passwords do not match");
            context.addMessage("tmpUsersForm:confirmField:confirm", msg);

        }
    }
}
